﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Demo_键盘监听
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            KeyboardScanInit();
        }

        #region 键盘监听

        public bool IsRece = true;

        public CsScanerHook m_Listener = new CsScanerHook();

        private void KeyboardScanInit()
        {
            m_Listener.ScanerEvent += Listener_ScanerEvent;
            m_Listener.Start();
        }

        private void Listener_ScanerEvent(CsScanerHook.ScanerCodes codes)
        {
            //dgv_lst.Rows.Add(new object[] { codes.KeyDownCount, codes.Event.message, codes.Event.paramH, codes.Event.paramL, codes.CurrentChar, codes.Result,   codes.isShift, codes.CurrentKey });

            if (IsRece)
            {
                //var nIndex = codes.Event.message;
                //Debug.WriteLine(string.Format("message:{0}", nIndex));

                //nIndex = codes.Event.paramH;
                //Debug.WriteLine(string.Format("paramH:{0}", nIndex));

                //nIndex = codes.Event.paramL;
                //Debug.WriteLine(string.Format("paramL:{0}", nIndex));

                //nIndex = codes.KeyDownCount;
                //Debug.WriteLine(string.Format("KeyDownCount:{0}", nIndex));

                //var str = codes.CurrentChar;
                //Debug.WriteLine(string.Format("CurrentChar:{0}", str));

                //str = codes.CurrentKey;
                //Debug.WriteLine(string.Format("CurrentKey:{0}", str));

                //var bRet = codes.isShift;
                //Debug.WriteLine(string.Format("isShift:{0}", bRet));

                var strResult = codes.Result;
                Debug.WriteLine(string.Format("【键盘监听事件】Result:{0}", strResult));
                Text.Text = string.Format("【键盘监听事件】\r\n Result:{0}", strResult);

            }
            var task1 = new Task(() =>
            {
                Console.WriteLine("Hello,task");
            });
            task1.Start();

            var task2 = Task.Factory.StartNew(() =>
            {
                Console.WriteLine("Hello,task started by task factory");
            });
            Task.WaitAll(task1, task2);

        }

        #endregion












    }





}
